package com.explorati.LeetCode704.search;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 20:30 2020/9/13 0013
 * @ Description ：
 */
public class Solution1 {
    public int search(int[] nums, int target) {
        if(nums.length == 0) {
            return -1;
        }
        int left = 0;
        int right = nums.length - 1;

        int mid = 0;
        while(left <= right) {
            mid = (right + left) / 2;
            if(nums[mid] > target) {
                right = mid - 1;
            }else if(nums[mid] < target) {
                left = mid + 1;
            }else {
                return mid;
            }
        }
        return -1;
    }
}
